package com.zengyan.gd.utils;

import com.zengyan.gd.core.ServiceException;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;

public class FileUtils {



    public static void isEmply(MultipartFile file) {
        if (file.isEmpty()) {
            throw new ServiceException("文件为空");
        }
    }

    /**
     * @param file
     * @return 得到后缀名
     */
    public static String getSuffix(MultipartFile file) {
        String fileName = file.getOriginalFilename();
        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
        return suffix;
    }

    public static void isParentExists(File dest) {
        if (!dest.getParentFile().exists()) {
            dest.getParentFile().mkdirs();
        }
    }

    static String getfilePath(String message, String suffix) {
        return ImageUtils.ImagePath + message + "." + suffix;
    }

    public static String getFileUrl(File file) {
        return "http://127.0.0.1:8889/static/" + file.getName();
    }

}
